<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>小黑的书架-1</title>
</head>

<body>
    <div id="app">
        <h3>小黑的书架</h3>
        <ul>
            <!-- 1.渲染页面 每个li都要配合key-->
            <li v-for="e in booksList" :key="e.id">
                <span>{{e.name}}</span>
                <span>{{e.author}}</span>
                <!-- 2.删除功能 点击事件 获取对应id删除 传参数  -->
                <button @click="del(e.id)">删除</button>
            </li>
        </ul>
    </div>
    <script src="./vue.js"></script>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                booksList: [
                    { id: 1, name: '《红楼梦》', author: '曹雪芹' },
                    { id: 2, name: '《西游记》', author: '吴承恩' },
                    { id: 3, name: '《水浒传》', author: '施耐庵' },
                    { id: 4, name: '《三国演义》', author: '罗贯中' }
                ]
            },
            methods: {
                // 删除事件函数
                del(id) {
                    // 筛选出所有满足不等于点击的id的对象形成新的数组赋值给原数组继续渲染
                    this.booksList = this.booksList.filter(e => id !== e.id)
                }
            }
        })
    </script>
</body>

</html>